from django.shortcuts import render
from .models import *
from rest_framework.response import Response
from rest_framework.views import APIView
# Create your views here.
import re

class UserM(APIView):
    def post(self,request):
        username = request.data.get('username')
        if username:
            return Response({'code':10010})
        reg = re.match('\w{5,10}$', username)
        if not reg:
            return Response({'code': 10011})
        user = User.objects.filter(username=username).first()
        if user:
            return Response({'code': 10012})

        mobile = request.data.get('mobile')
        if not mobile:
            return Response({'code': 10013})
        mreg = re.match('^1[3-9]\d{9}$', mobile)
        if not mreg:
            return Response({'code': 10014})
        mob = User.objects.filter(mobile=mobile).first()
        if mob:
            return Response({'code': 10015})
        return Response({'code':200})